<template>
	<view class="">		
		<view class="cu-card article" >
			<!--地址管理开始-->
			<view class="cu-item shadow bg-white" @tap="goAddress">
				<view class="nav-title">
					<text class="margin-lr-xs text-bold">{{mine[0].name}}</text>
					<text class="">{{mine[0].phone}}</text>
				</view>				
				<view class="content">
					<view class="nav-address">
						<text class="cuIcon-locationfill text-orange"></text>
					</view>
					<view class="desc">
						<view class="nav-content">{{mine[0].address}}</view>
					</view>
					<view class="nav-more">
						<text class="cuIcon-right"></text>
					</view>
				</view>
			</view>
			<!--地址管理结束-->
			<!--标签开始-->
			<view class=" bg-white shadow cu-item">				
				<view class="flex justify-start cu-form-group margin-top-sm">
					<view class="cu-tag bg-green light margin-lr-xs">拼团专享</view>
					<input :placeholder="inputPlaceholder" name="input" :value="ptCode"></input>						
				</view>
				
			</view>	
			<!--标签结束-->
			<!--商品栏开始-->
			<view class=" bg-white shadow cu-item ">
				<view class="content margin-top">
					<image :src="goods.ptGoodsThnmb"
					 mode="aspectFill"></image>
					 <view class="desc">
					 	<view class="text-content">{{goods.content}}</view>
					 	<view class="flex justify-start">
					 		<view class="cu-tag bg-green light sm" style="margin-top: 20upx;">免运费</view>
							<view class="margin-lr-xs">原价：
							<text class="text-price text-red text-xl"></text>
							<text class="text-red">{{goods.price}}元</text>
							</view>
					 	</view>
					 </view>
				</view>
			</view>	
			<!--商品栏结束-->
			<!--标签开始-->
			<view class=" bg-white shadow cu-item padding">
				<view class="flex justify-between">
					<view class="margin-lr-xs">平台优惠</view>
					<view class="margin-lr-xs">拼团优惠{{goods.price-goods.ptPrice}}元</view>
				</view>
			</view>	
			<!--标签结束-->
			<!--微信支付开始-->
			<view class=" bg-white shadow cu-item padding ">
				<view class="flex justify-between">
					<view class="margin-lr-xs">
						<text class="text-green cuIcon-weixin"></text>微信支付
						</view>
					<view class="cuIcon-check text-bold"></view>
				</view>

			</view>	
			<!--微信支付结束-->
			<!--。。。。。。。。。。。。订单测试开始-->
			<view class=" bg-white shadow cu-item padding ">
				<view class="flex justify-center">
					<view class="cu-btn round bg-red margin-lr-xs" @click="handldSub">测试支付成功</view>
					<view class="cu-btn round bg-red margin-lr-xs" @click="handError">测试支付失败</view>
				</view>
			
			</view>	
			<view class="cu-tabbar-height"></view>
			<!--。。。。。。。。。。。。订单测试结束-->
			
		</view>
		
		<!--底部栏开始-->
		<view class="cu-bar bg-white foot tabbar">
			<view class="basis-lg  padding-sm justify-end flex">
				<view>
					<text class="margin-lr-xs">实付款:</text>
					<text class="text-price text-red text-xxl "></text>
					<text class="text-red text-xl ">{{goods.ptPrice}}</text>
					<text class=" text-red margin-lr-xs">元</text>
				</view>
			</view>
			<!-- <view class=" bg-red submit" @tap="goCollageShare"> -->
			<view class=" bg-red submit">
				<text class="">立即支付</text>				
			</view>
		</view>
		<!--底部栏结束-->
	</view>
</template>

<script>
	export default{
		data(){
			return{
				mine:[],
				/*mine_test:[
					{
					    "id": 1,
					    "address": "广东省珠海市金湾区吉林大学珠海学院",
					    "name": "欧JJ",
					    "phone": "100861153",
					    "uid": 6
					},
				],*/
				goodsId:0,
				goods:{},
				inputPlaceholder:'输入拼团邀请码',
				ptCode:null,
			}
		},
		mounted() {
			this.getMine();
		},
		onLoad(option) {
			this.goodsId=option.goodsId;
			this.goods=JSON.parse(decodeURIComponent(option.goods));
			this.judgeCode(option.ptCode)
			//console.log(option.ptCode)
			//console.log(this.goods)
			//console.log(this.goodsId)
		},
		methods:{
			getMine(){
				this.request({
				  url:
				    this.apiServer +
				    "/address/findAddressByUId?uId=" +uni.getStorageSync("user").id
				}).then(res => {
				  console.log(res);
				  this.mine = res.data;
				});
			},
			judgeCode(Code){//判断ptCode
				if(Code!=0)
				{
					this.ptCode=Code;
				}
			},
			goCollageShare(){//参与拼单
				//console.log(this.goods[index].id)
				uni.navigateTo({
					url: '../collageShare/index',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			goAddress(){//设置地址页面
				uni.navigateTo({
					url:`/pages/mine/mine-areas/mine-areas`,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			//---------------------------测试订单开始
			handSuccess() {
			  this.request({
			    url: this.apiServer + "/pay/paidPayById",
			    method: "PUT",
			    data: {
			      id: this.payId
			    },
			    header: {
			      "Content-Type": "application/x-www-form-urlencoded"
			    }
			  }).then(res => {
			    console.log(res);
			  });
			
			  uni.showToast({
			    title: "支付成功!",
			    icon: "success"
			  });
			  uni.navigateTo({
			    url: '../collageShare/index'
			  });
			},
			handError() {
			  uni.showToast({
			    title: "支付失败!",
			    image: '/static/icon/error.png'
			  });
			},
			handldSub() {
				if(this.ptCode==null)
				{
					this.request({
					  url: this.apiServer + "/ptInfo/addTzPtInfo?status=已支付",
					  method: "POST",
					  data: {
					    uId: uni.getStorageSync("user").id,
					    ptGoodsId: this.goodsId,
					    ptGoodsName: this.goods.ptGoodsName,
						perPrice:this.goods.price,
					    Price: this.goods.ptPrice,
						name:this.mine[0].name,
						city:this.mine[0].address,
						tel:this.mine[0].phone
					  },
					  header: {
					    "Content-Type": "application/x-www-form-urlencoded"
					  }
					}).then(res => {
					  console.log("addpay");
					  console.log(res);
					  uni.showToast({
					    title: "支付成功!",
					    icon: "success"
					  });
					  uni.navigateTo({
					    url: '../collageShare/index?ptCode='+res.data.ptCode
					  });
					});
				}else{
					this.request({
					  url: this.apiServer + "/ptInfo/addTyPtInfo?status=已支付",
					  method: "POST",
					  data: {
					    uId: uni.getStorageSync("user").id,
					    ptGoodsId: this.goodsId,
					    ptGoodsName: this.goods.ptGoodsName,
						perPrice:this.goods.price,
					    Price: this.goods.ptPrice,
						name:this.mine[0].name,
						city:this.mine[0].address,
						tel:this.mine[0].phone,
						ptCode:this.ptCode
					  },
					  header: {
					    "Content-Type": "application/x-www-form-urlencoded"
					  }
					}).then(res => {
					  console.log("addpay");
					  console.log(res);
					  uni.showToast({
					    title: "支付成功!",
					    icon: "success"
					  });
					  uni.navigateTo({
					    url: '../collageShare/index?ptCode='+this.ptCode
					  });
					});
				}

			}
			//----------------------------测试订单结束
		}
	}
</script>

<style>
	.nav-title {
		margin-left: 90rpx;
		font-size: 30upx;
		color: #333333;
		line-height: 100upx;
		padding: 0 30upx;
	}
	.nav-address {
		width: 80rpx;
		font-size: 50upx;
		margin-right: 20rpx;
		border-radius: 6rpx;
	}
	.nav-more {
		font-size: 50upx;
		margin-left: 20rpx;
		border-radius: 6rpx;
	}
	.nav-content {
		font-size: 28upx;
		color: #888;
		overflow: hidden;
	}
	
</style>
